home *** CD-ROM | disk | FTP | other *** search
-
- ' ZBasic 5.0 and FutureBASIC TEFind Function
- ' 68x0 Assembler - Michael Burton, 1991,1992
- ' Michael Lininger, 1991,1992
-
-
- DIM T,B,L,R :' General Box Record Structure
-
-
- GOTO "Main_Start"
-
-
- LONG FN TEFind(TEFCharPtr&,TEFCharLen&,TEFFindStr$)
-
- ' Last Modified (4/20/91)
- ' Long Function (© 4/91 • Michael Burton •)
- ' (© 4/91 • Michael Lininger •)
-
- Found% = 0
- TEFFndLen = LEN(TEFFindStr$) :' Length of search string
- :' HI & LO word of REGISTER D0
- TEFCmpLen& = (TEFFndLen<<16)+TEFFndLen :' must equal length
- TEFCmpPtr& = VARPTR(TEFFindStr$)+1 :' Pointer to search string
- :' Loop from start of text to
- :' end minus search length
- TEFEnd& = TEFCharLen&-TEFFndLen :' Bytes to check
- :' This sets up the toolbox trap
- :' for "_cmpString"
- REGISTER(A0) = TEFCharPtr& :' Pointer #1 to Addr register 0
- REGISTER(A1) = TEFCmpPtr& :' Pointer #2 to Addr register 1
- REGISTER(D1) = TEFEnd& :' Bytes to check
- REGISTER(D2) = TEFCmpLen& :' Copied to D0 when needed
- MACHLG &1611 :' MOVE.B (A1),D3 ;first char of find str
- MACHLG &0203 :' ANDI.B #$1F,D3 ;ignore case
- MACHLG &001F
- MACHLG &1010 :'@loop: MOVE.B (A0),D0 ;current char
- MACHLG &0200 :' ANDI.B #$1F,D0 ;ignore case
- MACHLG &001F
- MACHLG &B600 :' CMP.B D0,D3 ;possible match?
- MACHLG &6608 :' BNE @next ; skip if not
- MACHLG &2002 :' MOVE.L D2,D0 ;use length
- MACHLG &A03C :' _CmpString
- MACHLG &4A80 :' TST.L D0 ;got a match?
- MACHLG &6708 :' BEQ @done ; exit if so
- MACHLG &5288 :'@next: ADDQ.L #1,A0 ;else point to next
- MACHLG &51C9 :' DBRA D1,@loop ;loop 'til done
- MACHLG &FFEA
- MACHLG &50C0 :' ST D0 ;note failure
- MACHLG &4E71 :'@done: NOP ;just a placeholder
- X = REGISTER(D0) :' D0 = non-zero if different and 0 if same
- TEFPtr& = REGISTER(A0) :' Last address checked
- LONG IF X = 0 :' If match found
- TEFSelStart = TEFPtr&-TEFCharPtr& :' Start @ current pointer
- TEFSelEnd = TEFPtr& :' Select the "found" text
- Found% = 1
- END IF
-
- END FN = Found%
-
-
- LONG FN getText$(dPtr&,whichItem%,Size%)
- CALL GETDITEM(dPtr&,whichItem%,theType%,theTxtHandle&,T)
- CALL GETITEXT(theTxtHandle&,theText$)
- LONG IF Size% > 0
- theText$ = LEFT$(theText$,Size%)
- END IF
- END FN = theText$
-
-
- LONG FN setText(dPtr&,whichItem%,theText$)
- CALL GETDITEM(dPtr&,whichItem%,theType%,theTxtHandle&,T)
- CALL SETITEXT(theTxtHandle&,theText$)
- END FN = 0
-
-
- LONG FN frameDLOGBtn(dPtr&,whichItem%)
- oldPort& = WINDOW(14) :' Store the old window grafport so we can restore it
- CALL SETPORT(dPtr&) :' Set the current dialog window as the active grafport
- CALL GETDITEM(dPtr&,whichItem%,theType%,theHandle&,T)
- CALL INSETRECT(T,-4,-4)
- CALL PENNORMAL:PEN 3,3
- CALL FRAMEROUNDRECT(T,16,16)
- CALL PENNORMAL
- CALL SETPORT(oldPort&) :' Restore the old window grafport as the new active one
- END FN = 0
-
-
- "Main_Start"
-
- ' (Sample 6/92 • Michael Lininger •)
-
- ' This demo code shows how to scan a TEXT file for a selected text match. This
- ' can be converted to scan a TE Edit Field for a match, or even to a find and
- ' replace. In this demo we just scan a text file of any size and count the number
- ' of matches and print the total to the screen.
-
- DLOGHndl& = FN GETRESOURCE(CVI("DLOG"),8128) :' Get Handle to DLOG 8128
- LONG IF DLOGHndl& = 0 :' If Z5, Non Project FB or DLOG 8128 not found
- DLOGFile$ = "COUNTERPoint™:TEFind.RES" :' Where is the TEFind Resource located
- ResRef% = FN OPENRESFILE(DLOGFile$) :' Open the Resource with the DLOG 8128
- XELSE
- CALL RELEASERESOURCE(DLOGHndl&)
- END IF
- OSErr% = FN RESERROR :' Clear any Resource Errors, Should be 0
-
- ' Get the Text String to search for...
- TEFindStr$ = "Sample Text"
- done% = 0
- DO
- dlogPtr& = FN GETNEWDIALOG(8128,0,-1)
- OSErr% = FN setText(dlogPtr&,3,TEFindStr$)
- l% = LEN(TEFindStr$)
- CALL SELITEXT(dlogPtr&,3,0,l%)
-
- DO
- FN frameDLOGBtn(dlogPtr&,1)
- more% = 0
- CALL MODALDIALOG(0,ctrlValue%)
- SELECT ctrlValue%
- CASE 1
- TEFindStr$ = FN getText$(dlogPtr&,3,25)
- more% = -1
- CASE 2
- more% = -2
- END SELECT
- UNTIL more%
- CALL DISPOSDIALOG(dlogPtr&)
-
-
- LONG IF TEFindStr$ <> "" AND more% <> -2
-
- fileName$ = FILES$(1,"TEXT",,Vol%) :' Get TEXT file to process
- LONG IF fileName$ > ""
- OPEN "R",1,fileName$,0,Vol%
- workSize& = 0
- tCount% = 0
- Length& = LOF(1,1) :' Get length of the file to work on
-
- LONG IF Length& > 32000 :' Do we need to process multiple blocks
- Bytes& = 32000
- XELSE
- Bytes& = LOF(1,1)
- END IF
-
- t& = TIMER :' Lets time the search
- DO
- CLEAR Bytes&,4 :' Clear (set aside) Space _newHandle
- RECORD #1,0,workSize& :' Position pointer, in case multiple reads
- READ FILE #1,MEM(4+40),Bytes& :' Block Read file section into _newHandle
-
- workBytes& = Bytes&
- useBytes& = Bytes&
- work& = 0
- TEFCharPtr& = MEM(4+40) :' Get pointer to text
- DO
- Found% = FN TEFind(TEFCharPtr&,useBytes&,TEFindStr$)
- LONG IF Found%
- fCount% = fCount% + 1
- work& = work& + TEFSelStart + LEN(TEFindStr$)
- TEFCharPtr& = MEM(4+40) + work& :' Get pointer to text
- useBytes& = workBytes& - work&
- END IF
- UNTIL Found% = 0
-
- workSize& = workSize& + Bytes& :' Update file pointer
- LONG IF workSize& + Bytes& > Length&
- Bytes& = Length& - workSize& :' Bytes left to process
- END IF
- UNTIL Bytes& = 0 :' No more bytes in file to process
- CLOSE #1
- CLEAR 0,4 :' Free up space _newHandle
-
- work& = TIMER - t& :' How long it took to scan the TEXT file
- CLS :' Print the Results
- PRINT " File Length:";
- PRINT USING "#,###,###";Length&;
- PRINT " Bytes Scanned:";
- PRINT USING "#,###,###";Length&/work&;
- PRINT " bytes/second"
- PRINT "Search String: ";TEFindStr$
- PRINT " File Info: ";fileName$;" Number of Matches:";fCount%;" Second(s):";
- LONG IF work& < 1
- PRINT " < 1"
- XELSE
- PRINT USING "###";work&
- END IF
- END IF
- XELSE
- done% = -1
- END IF
-
- UNTIL done%
-
- IF ResRef% <> 0 THEN CALL CLOSERESFILE(ResRef%) :' If in Z5, Close External Resource File
-
- END
-